package com.td.module.farmer.dal.mysql.management;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.td.framework.common.pojo.PageResult;
import com.td.framework.mybatis.core.mapper.BaseMapperX;
import com.td.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.td.module.farmer.controller.admin.management.vo.ManagementExportReqVO;
import com.td.module.farmer.controller.admin.management.vo.ManagementPageReqVO;
import com.td.module.farmer.dal.dataobject.management.ManagementDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 农户土地信息 Mapper
 *
 * @author 王翔翔
 */
@Mapper
public interface ManagementMapper extends BaseMapperX<ManagementDO> {

    default PageResult<ManagementDO> selectPage(ManagementPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ManagementDO>()
                .eqIfPresent(ManagementDO::getFarmerCode, reqVO.getFarmerCode())
                .likeIfPresent(ManagementDO::getName, reqVO.getName())
                .eqIfPresent(ManagementDO::getMobile, reqVO.getMobile())
                .eqIfPresent(ManagementDO::getAgroProductType, reqVO.getAgroProductType())
                .eqIfPresent(ManagementDO::getLandType, reqVO.getLandType())
                .orderByDesc(ManagementDO::getId));
    }

    default List<ManagementDO> selectList(ManagementExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ManagementDO>()
                .eqIfPresent(ManagementDO::getFarmerCode, reqVO.getFarmerCode())
                .likeIfPresent(ManagementDO::getName, reqVO.getName())
                .eqIfPresent(ManagementDO::getMobile, reqVO.getMobile())
                .eqIfPresent(ManagementDO::getAgroProductType, reqVO.getAgroProductType())
                .eqIfPresent(ManagementDO::getLandType, reqVO.getLandType())
                .betweenIfPresent(ManagementDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ManagementDO::getId));
    }

    default ManagementDO selectByMobile(String mobile) {
        return selectOne(new LambdaQueryWrapper<ManagementDO>().eq(ManagementDO::getMobile, mobile));
    }

    default ManagementDO selectByFarmerCode(String farmerCode) {
        return selectOne(new LambdaQueryWrapper<ManagementDO>().eq(ManagementDO::getFarmerCode, farmerCode));
    }

}
